package nz.ac.massey.xTarsier.structure;

/**
 * This takes a java.io.File and turns it into a format that is able to be parsed to JXPath
 * where it can then be searched using JXPath.
 * 
 * The dtd for the XML document that comes out is
 * <!DOCTYPE files [
 * <!ELEMENT files (name,absolutePath,files*|fileSize,file)>
 * <!ELEMENT name      (#PCDATA)>
 * <!ELEMENT absolutePath    (#PCDATA)>
 * <!ELEMENT files (#PCDATA)>
 * <!ELEMENT file    (#PCDATA)>
 *]>
 *
 *files is the root and an attribute that folders have
 *file is a boolean and is true if it is a file
 *name is the name of the file
 *absoloutePath is the path of the file
 * fileSize is the size in byte of the file
 * @author gdjenson
 *
 */
public class FileConverter {
	
	public static SystemFile convertFile(java.io.File file)
	{

	SystemFile sFile = convertFiles(file);
	return sFile;
	}
	
	private static SystemFile convertFiles(java.io.File file)
	{
		if (file.isFile())
		{
			return new File(file.getAbsolutePath(),file.getName(),file.length());
			
		}
		else
		{
			Folder newFolder = new Folder(file.getAbsolutePath(), file.getName());
			for(java.io.File f : file.listFiles())
			{
			newFolder.addSystemFile(convertFiles(f));
			}
			return newFolder;
		}
	}
	
}
